package com.eight.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.common.pojo.Order;
import com.eight.common.pojo.TbPlayHistory;
import com.eight.common.vo.Result;
import com.eight.order.service.OrderService;
import com.eight.order.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: qy8-education
 * @description:
 * @author: 郑友民（1460115388@qq.com）
 * @create: 2023-06-01 20:08
 **/
@RestController
@RequestMapping("/order")
@Api("订单信息")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/order/getAllOrder/{current}/{pageSize}")
    @ApiOperation("条件分页查询订单")
    public Result getAllOrder(@PathVariable Integer current, @PathVariable Integer pageSize, @RequestBody OrderVo orderVo) {
        Page<Order> orderPage = orderService.getAllOrder(current, pageSize, orderVo);
        return Result.success(orderPage);
    }

    @DeleteMapping("/order/deleteOrder/{id}")
    @ApiOperation("删除订单")
    public Result deleteOrder(@PathVariable String id) {
        int i = orderService.deleteOrder(id);
        if (i > 0) {
            return Result.success();
        }
        return Result.fail();
    }

    @PostMapping("/pay/createWeiXin/{courseId}/{HuiYuanId}")
    @ApiOperation("微信支付")
    public Result createWeiXin(@PathVariable String courseId, @PathVariable String HuiYuanId) {

        return orderService.createWeiXin(courseId, HuiYuanId);
    }



    @PostMapping("/pay/getPayStatus/{out_trade_no}")
    @ApiOperation("获取支付状态")
    public Result getPayStatus(@PathVariable String out_trade_no) {

        return orderService.getPayStatus(out_trade_no);
    }


    @PostMapping("/play-history/queryPlayHistoryBy/{currentPage}/{pageCount}/{id}")
    @ApiOperation("条件分页查询学习记录")
    public Result queryPlayHistoryBy(@PathVariable Integer currentPage, @PathVariable Integer pageCount, @PathVariable String id) {
        Page<TbPlayHistory> historyPage = orderService.queryPlayHistoryBy(currentPage, pageCount, id);
        return Result.success(historyPage);
    }
}

